﻿using CommunityToolkit.Mvvm.ComponentModel;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ListCompareDemo.Models
{
    public partial class RecipeScanPoint : ObservableObject
    {
        public int Id { get; set; }

        public int Ordinal { get; set; }

        public int X { get; set; }

        public int Y { get; set; }

        public double Dx { get; set; }

        public double Dy { get; set; }

        public int PatternId { get; set; }

        public int PatternOrdinal { get; set; }

        public string Name { get; set; } = "";

        public bool HasParent { get; set; }

        public int ParentId { get; set; }

        public double BaseDx { get; set; }

        public double BaseDy { get; set; }

        public string MP => "MP" + PatternOrdinal;

        public string Type => HasParent ? "D" : "";

        [ObservableProperty]
        [NotifyPropertyChangedFor(nameof(UserDx))]//表示:UserDx会在isInOrder变更时更新
        [NotifyPropertyChangedFor(nameof(UserDy))]
        bool isInOrder;

        /// <summary>
        /// 修改了Origin之后 原来的点是否还在图里
        /// </summary>
        [ObservableProperty]
        bool isOutOfMap;

        public string UserDx => IsInOrder ? $"{(Dx - BaseDx) * 1000:0.###}" : "";

        public string UserDy => IsInOrder ? $"{(Dy - BaseDy) * 1000:0.###}" : "";

        public RecipeScanPoint Copy()
        {
            return new RecipeScanPoint
            {
                Id = this.Id,
                Ordinal = this.Ordinal,
                X = this.X,
                Y = this.Y,
                Dx = this.Dx,
                Dy = this.Dy,
                PatternId = this.PatternId,
                PatternOrdinal = this.PatternOrdinal,
                Name = this.Name,
                HasParent = this.HasParent,
                ParentId = this.ParentId,
                BaseDx = this.BaseDx,
                BaseDy = this.BaseDy,
                IsInOrder = this.IsInOrder
            };
        }
    }


    public class ScanPoint
    {
        public int X { get; set; }

        public int Y { get; set; }

        public double Dx { get; set; }

        public double Dy { get; set; }

        public double AddrOffsetX { get; set; }

        public double AddrOffsetY { get; set; }

        public int PatternIndex { get; set; }
    }

}
